﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class FrmDTerminalMark : System.Windows.Forms.Form
	{
		public FrmDTerminalMark()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			this.tagOperate = new HYTagOperate();
		}

		private void FrmDTerminalMark_Load(object sender, EventArgs e)
		{
			if (this.tagOperate.GetNodeValue("DTerminal", "isHaveFlow") == "Yes")
			{
				this.ckbFlow.Checked = true;
				this.SetImage("style2");
			}
			else
			{
				this.ckbFlow.Checked = false;
				this.SetImage("style1");
			}
			if (this.tagOperate.GetNodeValue("DTerminal", "bHasPrefix") == "Yes")
			{
				this.chkTerminalPrefix.Checked = true;
			}
			else
			{
				this.chkTerminalPrefix.Checked = false;
			}
			//base.Icon = Resource.YArchitechIcon;
		}

		private void SetImage(string name)
		{
			string terminalImagePath = this.tagOperate.GetTerminalImagePath(name);
			this.btnImage.BackgroundImage = Image.FromFile(terminalImagePath);
		}

		private void ckbFlow_CheckedChanged(object sender, EventArgs e)
		{
			if (this.ckbFlow.Checked)
			{
				this.SetImage("style2");
				return;
			}
			this.SetImage("style1");
		}

		private void btnMark_Click(object sender, EventArgs e)
		{
			if (this.ckbFlow.Checked)
			{
				this.isHaveFlow = true;
				this.tagOperate.SetNodeValue("DTerminal", "isHaveFlow", "Yes");
			}
			else
			{
				this.isHaveFlow = false;
				this.tagOperate.SetNodeValue("DTerminal", "isHaveFlow", "No");
			}
			if (this.chkTerminalPrefix.Checked)
			{
				this.bHasPrefix = true;
				this.tagOperate.SetNodeValue("DTerminal", "bHasPrefix", "Yes");
			}
			else
			{
				this.bHasPrefix = false;
				this.tagOperate.SetNodeValue("DTerminal", "bHasPrefix", "No");
			}
			this.tagOperate.SaveXml();
			base.DialogResult = DialogResult.Yes;
		}

		private void btnCancle_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		public bool isHaveFlow;

		public bool bHasPrefix;

		private HYTagOperate tagOperate;
	}
}
